#
# print("""
# ***************************************
#         驻波要发神经！！！！！！！！！
# ***************************************
# """)
#
# def create_write_file():
#     filename = input("请输入文件名：")
#     text = input("请输入要写入的文本：")
#     file = open(filename, "w")
#     file.write(text)
#     file.write(text)
#     print(f"文件{filename}已创建并写入文本")
#
# def read_file():
#     filename = input("请输入一个文件名：")
#     try:
#         file = open(filename,"r")
#         content = file.read()
#         print("文件内容为：",content)
#     except FileNotFoundError:
#         print(f"{filename}未找到")
# def append_to_file():
#     filename = input("文件名：")
#     text = input("请输入要追加的内容：")
#     try:
#         file = open(filename, "a")
#         file.write(text)
#         '''
#         with open(filename, "a") as file:
#             file.write(text)
#         '''
#         print(f"{file}已追加到文件{filename}")
#     except FileNotFoundError:
#         print(f"文件{filename}不存在")
# def myNotebook():
#     while True:
#     print("****我的简单记事本bug****")
#     print("****1.创建并写入文件*****")
#     print("****2.读取文件**********")
#     print("****3.追加文本到文件*****")
#     print("****4.退出！***********")
#
#     choice = input("请输入选项编号:")
#     if choice == "1":
#         create_write_file()
#     elif choice == "2":
#         read_file()#
#     elif choice == "3":
#         append_to_file()#
#     elif choice == "4":
#         print("退出记事本bug")
#         break
# if __name__ == '__main__':
#     print(f"__name__的值为：{__name__}")
#     myNotebook()
#
#

# 记事本
print("""
***************************************
        驻波要发神经！！！！！！！！！
***************************************
""")
def create_write_file():
    filename = input("请输入文件名：")
    text = input("请输入要写入的文本：")
    file = open(filename, "w")
    file.write(text)
    file.write(text)
    print(f"文件{filename}已创建并写入文本")


def read_file():
    filename = input("请输入要读取的文件名：")
    try:
        file = open(filename, "r")
        content = file.read()
        print(f"文件{filename}的内容为：\n{content}")
    except FileNotFoundError:
        print(f"文件{filename}不存在")


def append_to_file():
    filename = input("请输入要追加文本的文件名：")
    text = input("请输入要追加的文本：")
    try:
        file = open(filename, "a")
        file.write(text)
        '''
        with open(filename, "a") as file:
            file.write(text)
        '''
        print(f"{file}已追加到文件{filename}")
    except FileNotFoundError:
        print(f"文件{filename}不存在")


def myNotebook():
    while True:
        print("★★★★★★★★★★记事本★★★★★★★★★★")
        print("*******1.创建并写入文件***********")
        print("**********2.读取文件*************")
        print("********3.追加文本到文件**********")
        print("************4.退出**************")

        choice = input("请输入你的选择：")
        if choice == "1":
            create_write_file()

        elif choice == "2":
            read_file()

        elif choice == "3":
            append_to_file()

        elif choice == "4":
            print("退出记事本")
            break


if __name__ == "__main__":  # 测试代码
    print(f"__name__的值为：{__name__}")
    myNotebook()